package cn.fan.redis;

import cn.fan.constants.RedisConstants;
import cn.fan.mapper.UserMapper;
import cn.fan.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

@Component
public class UserRedis {

    @Autowired
    private UserMapper userMapper;

    @Cacheable(value = "userId",key = "#userId")
    public User getById(long userId){
        return userMapper.selectById(userId);
//        return null;
    }

    @CachePut(value = RedisConstants.USER_CACHE_KEY,key = "#userId")
    public User putById(long userId){
        return userMapper.selectById(userId);
    }

    @CachePut(value = RedisConstants.USER_CACHE_KEY,key = "#userId")
    public User putByUser(long userId,User user){
        return user;
    }

    @CacheEvict(value = RedisConstants.USER_CACHE_KEY,key = "#userId")
    public void delete(long userId){

    }

}
